﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using SQLServerHelper;

namespace DataBaseHelper
{
    public partial class DataBaseLogin : Form
    {
        public DataBaseLogin()
        {
            InitializeComponent();
        }

        private void DataBaseLogin_Load(object sender, EventArgs e)
        {
            SQLServerManger oServerManger = new SQLServerManger();
            List<string> sSQLServerList = oServerManger.GetSQLServicesList();
            if (sSQLServerList!=null && sSQLServerList.Count>0)
            {
                SQL_Server.DataSource = sSQLServerList;
                SQL_Server.SelectedIndex = 0;
            }
            else
            {
                SQL_Server.Items.Add("<No available SQL Servers>");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string sSQLServer = SQL_Server.Text;
            string sLoginName = txtLoginName.Text;
            string sLoginPwd = txtLoginPwd.Text;
            if (!string.IsNullOrEmpty(sSQLServer) && !string.IsNullOrEmpty(sLoginName) && !string.IsNullOrEmpty(sLoginPwd))
            {
                SQLServerManger oServerManger = new SQLServerManger(sSQLServer,sLoginName,sLoginPwd);
                DataBaseHelperMain oMain = new DataBaseHelperMain();
                oMain.oManger = oServerManger;
                oMain.Show();
                this.Hide();
            }
            else
            {
                MessageBox.Show("输入数据错误，请检查");
            }
        }
    }
}
